package com.zhouhong;

import java.util.Arrays;

/**
 * @ClassName: Algorithm-and-Data-Structure
 * @Description: 在排序数组中查找比给定数大的最小值
 * @Author: zhouhong
 * @Create: 2021-04-08 00:54
 **/

// 在排序数组中查找比给定数大的最小值
public class SearchUpper {
    private SearchUpper(){}
    public static int upper(int[] arr, int target){
        int l = 0, r = arr.length;
        // 在 arr[l....r] 中寻找解
        while (l < r){
            int mid = l + (r - l) / 2;
            if (arr[mid] <= target){
                l = mid + 1;
            }else {
                r = mid;
            }
        }
        return l;
    }

    public static void main(String[] args) {
        int[] arr = {2,9,12,23,45,45,56,67,78,89,90};
        System.out.println(upper(arr, 50));
    }
}
